export function formatBytes(bytes: number): string {
  if (bytes === 0) return '0.00 bytes';

  const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB'] as const;
  let i = Math.floor(Math.log(bytes) / Math.log(1024));
  
  // 防止超过最大单位（例如超出 TB）
  if (i >= sizes.length) {
    i = sizes.length - 1;
  }

  const size = parseFloat((bytes / Math.pow(1024, i)).toFixed(2));
  return `${size} ${sizes[i]}`;
}
export function generateRandomString(length: number): string {
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  for (let i = 0; i < length; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return result;
}